package bean;

public class DefaultBeanDefinition implements BeanDefinition{
    private Class<?> beanClass;
    private String scope = SCOPE_SINGLETION;
    private String factoryBeanName;
    private String factoryMethodName;
    private String initMethodName;
    private String destroyMethodName;
    private boolean primary;
    // 通过构造函数注入必要属性
    public DefaultBeanDefinition(Class<?> beanClass) {
        String name = beanClass.getName();
        System.out.println(name + " be creating");
        this.beanClass = beanClass;
    }

    @Override
    public Class<?> getBeanClass() {
        return this.beanClass;
    }

    @Override
    public String getScope() {
        return this.scope;
    }

    public void setScope(String scope) {
        this.scope = (scope != null && !scope.trim().isEmpty()) ? scope : SCOPE_SINGLETION;
    }

    @Override
    public boolean isSingleton() {
        return SCOPE_SINGLETION.equals(this.scope);
    }

    @Override
    public boolean isPrototype() {
        return SCOPE_PROTOTYPE.equals(this.scope);
    }

    // 其他方法实现（根据业务需求选择是否添加setter）
    @Override
    public String getFactoryBeanName() {
        return this.factoryBeanName;
    }

    public void setFactoryBeanName(String factoryBeanName) {
        this.factoryBeanName = factoryBeanName;
    }

    @Override
    public String getFactoryMethodName() {
        return this.factoryMethodName;
    }

    public void setFactoryMethodName(String factoryMethodName) {
        this.factoryMethodName = factoryMethodName;
    }

    // 初始化/销毁方法
    @Override
    public String getInitMethodName() {
        return this.initMethodName;
    }

    public void setInitMethodName(String initMethodName) {
        this.initMethodName = initMethodName;
    }

    @Override
    public String getDestroyMethodName() {
        return this.destroyMethodName;
    }

    public void setDestroyMethodName(String destroyMethodName) {
        this.destroyMethodName = destroyMethodName;
    }

    @Override
    public boolean isPrimary() {
        return this.primary;
    }

    public void setPrimary(boolean primary) {
        this.primary = primary;
    }
}
